package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CirculationSheet;
import com.ruoyi.system.service.ICirculationSheetService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 流转单Controller
 * 
 * @author ruoyi
 * @date 2021-03-12
 */
@Controller
@RequestMapping("/system/sheet")
public class CirculationSheetController extends BaseController
{
    private String prefix = "system/sheet";

    @Autowired
    private ICirculationSheetService circulationSheetService;

//    @RequiresPermissions("system:sheet:view")
    @GetMapping()
    public String sheet()
    {
        return prefix + "/sheet";
    }

    /**
     * 查询流转单列表
     */
//    @RequiresPermissions("system:sheet:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CirculationSheet circulationSheet)
    {
        startPage();
        List<CirculationSheet> list = circulationSheetService.selectCirculationSheetList(circulationSheet);
        return getDataTable(list);
    }

    /**
     * 导出流转单列表
     */
    @RequiresPermissions("system:sheet:export")
    @Log(title = "流转单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CirculationSheet circulationSheet)
    {
        List<CirculationSheet> list = circulationSheetService.selectCirculationSheetList(circulationSheet);
        ExcelUtil<CirculationSheet> util = new ExcelUtil<CirculationSheet>(CirculationSheet.class);
        return util.exportExcel(list, "sheet");
    }

    /**
     * 新增流转单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存流转单
     */
    @RequiresPermissions("system:sheet:add")
    @Log(title = "流转单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CirculationSheet circulationSheet)
    {
        return toAjax(circulationSheetService.insertCirculationSheet(circulationSheet));
    }

    /**
     * 修改流转单
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CirculationSheet circulationSheet = circulationSheetService.selectCirculationSheetById(id);
        mmap.put("circulationSheet", circulationSheet);
        return prefix + "/edit";
    }

    /**
     * 修改保存流转单
     */
    @RequiresPermissions("system:sheet:edit")
    @Log(title = "流转单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CirculationSheet circulationSheet)
    {
        return toAjax(circulationSheetService.updateCirculationSheet(circulationSheet));
    }

    /**
     * 删除流转单
     */
    @RequiresPermissions("system:sheet:remove")
    @Log(title = "流转单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(circulationSheetService.deleteCirculationSheetByIds(ids));
    }
}
